package com.zhdl.common.eventbus.center;

import com.google.common.eventbus.AsyncEventBus;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class EventBusCenter {
//    private static EventBus eventBus;
//
//    //双重锁单例模式
//    public static EventBus getEventBus(){
//        if(eventBus==null){
//            synchronized (EventBus.class){
//                if(eventBus==null){
//                    eventBus = new EventBus();
//                }
//            }
//        }
//        return eventBus;
//    }

    private static AsyncEventBus asyncEventBus;
    private static Executor executor = Executors.newFixedThreadPool(10);

    //双重锁单例模式
    public static AsyncEventBus getEventBus() {
        if (asyncEventBus == null) {
            synchronized (AsyncEventBus.class) {
                if (asyncEventBus == null) {
                    asyncEventBus = new AsyncEventBus(executor);
                }
            }
        }
        return asyncEventBus;
    }


}